package com.ccl.iot.device;

import com.ccl.iot.object.IOTDeviceInfoEx;

public class IOTSwitch extends IOTDeviceWithState implements SwitchDevice{
	private final static String KSTATE_ID_LIST[] = {"0", "1"};
	
	public IOTSwitch(long aDevID, IOTDeviceInfoEx aDeviceInfo, int aSwitchAddress, int aSwitchSize){
		super(aDevID, aDeviceInfo, aSwitchAddress, aSwitchSize);
	}
	
	@Override
	public boolean isOn(){
		return iState != 0;
	}
	
	@Override
	public void turn(boolean aON){
		setState(aON ? 1 : 0);
	}

	@Override
	public String[] getStateIDs() {
		return KSTATE_ID_LIST;
	}

	@Override
	public int getImageId() {
		int id = getDevImgStyleID();

        return isOn()?DeviceIconProvider.ICON_LIST_SWITCH_ON[id]:DeviceIconProvider.ICON_LIST_SWITCH_OFF[id];
	}

	@Override
	public void onViewClick() {
		turn(!isOn());
	}


	/**
	 * 获取设备图片样式的下标
	 * @return
	 */
	public int getDevImgStyleID(){
		int id = getSplitIconId();
		if (id >= DeviceIconProvider.ICON_LIST_SWITCH_ON.length){
			id = 0;
		}
		return id;
	}
}
